package edu.xhxy;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class IntSumReducer extends Reducer <Text, IntWritable,Text,IntWritable> {
    protected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable,Text,IntWritable>.Context context) throws IOException, InterruptedException {
        int sum = 0;
        int c=0;
        for(IntWritable i : values)
        {
            c++;
            sum+=i.get();
        }
        context.write(key,new IntWritable(sum/c));
    }
}